package io.renren.modules.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.base.annotation.Login;
import io.renren.common.validator.ValidatorUtils;
import io.renren.modules.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;

import io.renren.modules.entity.ExpertEntity;
import io.renren.modules.service.ExpertService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * 专家
 *
 * @author xiaozhao
 * @email langzi2582@163.com
 * @date 2019-01-05 00:31:21
 */
@RestController
@RequestMapping("api")
@Api(tags = "专家接口")
public class ExpertController {
    @Autowired
    private ExpertService expertService;

    /**
     * 列表
     */
    @Login
    @PostMapping("expert/list")
    @ApiOperation("列表")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = expertService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */

//    @Login
//    @PostMapping("expert/info/{id}")
//    @ApiOperation("信息")
//
//    public R info(@PathVariable("id") Integer id){
//
////        ExpertEntity expert = expertService.selectById(id);
//
//        return R.ok().put("expert", expert);
//    }
    @Login
    @PostMapping("expert/info/{user_id}")
    @ApiOperation("信息")
    public R info(@PathVariable("user_id") String user_id) {
        ExpertEntity expert = expertService.queryByUserId(user_id);
        return R.ok().put("expert", expert);
    }

    /**
     * 保存
     */

    @Login
    @PostMapping("expert/save")
    @ApiOperation("保存")

    public R save(@RequestBody ExpertEntity expert) {
        expertService.insert(expert);

        return R.ok();
    }

    /**
     * 修改
     */
    @Login
    @PostMapping("expert/update")
    @ApiOperation("修改")

    public R update(@RequestBody ExpertEntity expert) {
        System.out.println(expert.getId()+expert.getUserId());
        ValidatorUtils.validateEntity(expert);
        expertService.updateAllColumnById(expert);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @Login
    @PostMapping("expert/delete")
    @ApiOperation("删除")
    public R delete(@RequestBody Integer[] ids) {
        expertService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
